﻿using ChoMy.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ChoMy.Areas.Admin.Controllers
{
    public class UserController : Controller
    {
        private ApplicationDbContext dba = new ApplicationDbContext();

        public UserController()
        {

        }

        public ActionResult Single(string partialView)
        {
            ApplicationUser user = dba.Users.FirstOrDefault(x => x.UserName == User.Identity.Name);

            return PartialView(partialView, user);
        }

        #region Helpers
        public bool UserInRoles(string roles)
        {
            List<string> lstRole = roles.Split(',').Select(x => x.Trim()).ToList();

            foreach(string role in lstRole)
            {
                if(User.IsInRole(role))
                {
                    return true;
                }
            }

            return false;
        }
        #endregion
    }
}